//
//  STRegisterViewController.swift
//  iPhone
//
//  Created by Toj on 4/25/23.
//

import UIKit

// MARK: - 懒加载(属性), 变量, 初始化init
class STRegisterViewController: STSignInBaseController {
    
    /* STRegisterGetCodeView */
    private lazy var getCodeView: STRegisterGetCodeView = {
        let view = STRegisterGetCodeView()
        view.delegate = self
        return view
    }()
    
    /* STRegisterSetupPwdView */
    private lazy var setupPasswordView: STRegisterSetupPwdView = {
        let view = STRegisterSetupPwdView()
        view.delegate = self
        view.isHidden = true
        return view
    }()
}

// MARK: - 生命周期
extension STRegisterViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupMakeInitialize()
        setupMakeAddSubviews()
        setupMakeLayoutSubviews()
    }
}

// MARK: - 数据请求
extension STRegisterViewController {
    
//    private func <#Function#>Request() {
//        showLoading()
//        request<#Function#>
//    }
}

// MARK: - 点击事件
@objc private extension STRegisterViewController {
    
}

// MARK: - Public
extension STRegisterViewController {
    
}

// MARK: - Private
private extension STRegisterViewController {
    
    func dismiss(view: UIView) {
        view.isHidden = true
        guard getCodeView.isHidden && setupPasswordView.isHidden else {
            return
        }
        navigationController?.popViewController(animated: true)
    }
}

// MARK: - 代理事件: STRegisterGetCodeViewDelegate
extension STRegisterViewController: STRegisterGetCodeViewDelegate {
    func registerGetCodeViewDidTapClose(_ getcodeView: STRegisterGetCodeView) {
        dismiss(view: getcodeView)
    }
    
    func registerGetCodeViewDidTapGetcode(_ getcodeView: STRegisterGetCodeView) {
        
    }
    
    func registerGetCodeViewDidInputFinished(_ getcodeView: STRegisterGetCodeView, code: String) {
        setupPasswordView.show()
    }
}

// MARK: - 代理事件: STRegisterSetupPwdViewDelegate
extension STRegisterViewController: STRegisterSetupPwdViewDelegate {
    
    func registerSetupPwdViewDidTapClose(_ setupView: STRegisterSetupPwdView) {
        dismiss(view: setupView)
    }
    
    func registerSetupPwdViewDidTapNext(_ setupView: STRegisterSetupPwdView, password: String) {
        let finishedView = STRegisterFinishView()
        view.addSubview(finishedView)
        finishedView.snp.remakeConstraints { make in
            make.edges.equalTo(view)
        }
    }
}

// MARK: - 初始化设置
private extension STRegisterViewController {
    
    func setupMakeAddSubviews() {
        view.addSubview(getCodeView)
        view.addSubview(setupPasswordView)
    }
    
    func setupMakeLayoutSubviews() {
        getCodeView.snp.makeConstraints { make in
            make.edges.equalTo(view)
        }
        
        setupPasswordView.snp.makeConstraints { make in
            make.edges.equalTo(view)
        }
    }
    
    func setupMakeInitialize() {
    
    }
}
